<template>
  <div class="social-platforms">
    <div class="social-platforms__wrapper">
      <div
        v-for="platform in platforms"
        :key="platform.id"
        class="social-platforms__item"
        :class="{ 'is-selected': selectedPlatforms.includes(platform.id) }"
        @click="togglePlatform(platform.id, platform.name)"
      >
        <div class="social-platforms__icon-container">
          <img
            :src="platform.icon"
            alt="Platform Icon"
            class="social-platforms__icon"
          />
        </div>
        <div class="social-platforms__name">{{ platform.name }}</div>
        <div
          v-show="selectedPlatforms.includes(platform.id)"
          class="social-platforms__close-icon"
          @click.stop="removePlatform(platform.id)"
        >
          <div>×</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
const ICON_PATH = {
  instagram: require("@/assets/SocialMetrics/instagram.png"),
  x: require("@/assets/SocialMetrics/X.png"),
  Linkedin: require("@/assets/SocialMetrics/Linkedin.png"),
  Reddit: require("@/assets/SocialMetrics/Reddit.png"),
  YouTube: require("@/assets/SocialMetrics/YouTube.png"),
  TikTok: require("@/assets/SocialMetrics/TikTok.png"),
  Threads: require("@/assets/SocialMetrics/Threads.png"),
  Google: require("@/assets/SocialMetrics/Google.png"),
  RedNote: require("@/assets/SocialMetrics/RedNote.png"),
  //   default: require("@/assets/default-icon.png"),
};
export default {
  data() {
    return {
      selectedPlatforms: [],
      platforms: [
        {
          id: 1,
          name: "Instagram",
          icon: ICON_PATH.instagram,
        },
        { id: 2, name: "X", icon: ICON_PATH.x },
        { id: 3, name: "Linkedin", icon: ICON_PATH.Linkedin },
        { id: 4, name: "Reddit", icon: ICON_PATH.Reddit },
        { id: 5, name: "YouTube", icon: ICON_PATH.YouTube },
        { id: 6, name: "TikTok", icon: ICON_PATH.TikTok },
        { id: 7, name: "Threads", icon: ICON_PATH.Threads },
        { id: 8, name: "Google", icon: ICON_PATH.Google },
        { id: 9, name: "RedNote", icon: ICON_PATH.RedNote },

        // 其他平台...
      ],
    };
  },

  methods: {
    togglePlatform(id, name) {
      // 点击时切换选中状态
      this.selectedPlatforms = this.selectedPlatforms.includes(id)
        ? this.selectedPlatforms.filter((pId) => pId !== id)
        : [...this.selectedPlatforms, id, name];
      console.log("选中的所有的值", this.selectedPlatforms);
    },
    removePlatform(id) {
      // 移除选中状态
      this.selectedPlatforms = this.selectedPlatforms.filter(
        (pId) => pId !== id
      );
    },
  },
};
</script>
<style scoped lang="scss">
.social-platforms {
  padding-top: 20px;
  display: flex;
  // 容器固定宽度，超出显示滚动条
  width: 100%;
  // overflow-x: auto; /* 横向滚动条 */

  .social-platforms__wrapper {
    display: flex;
    gap: 10px; /* 平台项间距 */
    white-space: nowrap; /* 禁止换行，保持单行滚动 */
    min-width: 100%; /* 撑满容器宽度 */
  }

  .social-platforms__item {
    position: relative;
    flex: 1 1 auto;
    flex: 0 0 calc((100% - (8 * 10px)) / 9);
    min-width: 80px;
    min-height: 50px;
    box-sizing: border-box;
    border-radius: 8px;
    border: 1px solid #cdcccc;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: all 0.2s ease;
    .social-platforms__icon-container {
      margin-right: 4px;
      .social-platforms__icon {
        width: 20px;
        height: 20px;
        img {
          height: 100%;
          width: 100%;
        }
      }
    }
    .social-platforms__name {
      font-size: 16px;
      font-weight: 600;
      color: #232323;
    }
    .social-platforms__close-icon {
      position: absolute;
      top: -15%;
      right: -5%;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background: #6a6969;
      color: #fff;
    }
  }
  // 定义滚动条高宽及背景，高宽分别对应横竖滚动条的尺寸
  // ::-webkit-scrollbar {
  //   width: 1px; // 滚动条宽度
  //   height: 1px; // 滚动条高度
  //   background-color: #fff; // 滚动条背景颜色
  // }

  // // 定义滚动条轨道，内阴影+圆角
  // ::-webkit-scrollbar-track {
  //   border-radius: 4px;
  //   background-color: #fff;
  // }

  // // 定义滑块，内阴影+圆角
  // ::-webkit-scrollbar-thumb {
  //   border-radius: 4px;
  //   background-color: #d9d9d9;
  //   border: 1px solid #d9d9d9;
  // }

  // // 定义滑块hover状态
  // ::-webkit-scrollbar-thumb:hover {
  //   background-color: #bbbbbb;
  //   border: 1px solid #bbbbbb;
  // }

  // // 定义滑块active状态
  // ::-webkit-scrollbar-thumb:active {
  //   background-color: #999999;
  //   border: 1px solid #999999;
  // }
  .social-platforms__item.is-selected {
    border: 2px solid #2d83ca;
    background-color: #d2ebff; // 浅蓝色背景
  }
}
</style>
